<?php
/**
* @author Bimal Poudel
* @copyright since 2006, Bimal Poudel
* @package Smarty Framework
* @support http://www.odesk.com/users/~~dd91d11caed0cdce
* @contact http://www.sanjaal.com
* @company Sanjaal Corps
*/

# Created on: 2011-03-26 02:03:52 890

/**
* Lists entities in posts
*/

# Begin the paginator along with: posts
# Parameter: GET[], and per page
$pagination = new pagination('pg', 3); # __PER_PAGE__

$posts = new posts();

$condition = new condition();

# Listed records that are bound to the current subdomain only
# $subdomain_id = framework::subdomain_id();

if(isset($_GET['category']))
{
	$_SESSION['category'] = (int)$_GET['category'];
}
else
{
	if(isset($_GET['reset']) && $_GET['reset']=='true')
	{
		$_SESSION['category'] = 0;
	}
	$_SESSION['category'] = isset($_SESSION['category'])?(int)$_SESSION['category']:0;
}
if($_SESSION['category'])
{
	$condition->add('FULL', array(
		"e.category_id={$_SESSION['category']}", # Bind the records
		"e.is_active='Y'", # Do not remove this
	));
}

$condition->add('FULL', array(
	#"e.subdomain_id={$subdomain_id}", # Bind the records
	"e.is_active='Y'", # Do not remove this
));

# Compulsory conditons
$condition->add('AND', array(
	#'e.search_field' => 'Y', # Partial %contents%
));

# List out the entries
$entries = $posts->list_entries(
	$condition,
	$from_index=$pagination->begining_entry(),
	$pagination->per_page()
);

# Pagination helper
$pagination->set_total($posts->total_entries());
$smarty->assignByRef('pagination', $pagination);

# Assign to Smarty: Lists
$smarty->assignByRef('microblogs', $entries);

# Counts the categories
$c = new categories();
$categories = $c->count_posts();
$smarty->assignByRef('categories', $categories);
?>